local chengshang = fk.CreateSkill {

  name = "joy__chengshang",

  tags = {  },

}



chengshang:addEffect(fk.CardUseFinished, {
  name = "joy__chengshang",
  anim_type = "drawcard",
  events = {fk.CardUseFinished},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(chengshang.name) and player.phase == Player.Play  and
      data.card.suit ~= Card.NoSuit and player:usedSkillTimes(chengshang.name, Player.HistoryPhase) == 0
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, chengshang.name, nil,
      "#joy__chengshang-invoke:::"..data.card:getSuitString()..":"..tostring(data.card.number))
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = room:getCardsFromPileByRule(".|"..tostring(data.card.number).."|"..data.card:getSuitString())
    if #cards > 0 then
      for _, cid in ipairs(cards) do
        room:setCardMark(Fk:getCardById(cid),"@@joy__chengshang-turn",1)
      end
      room:moveCards({
        ids = cards,
        to = player.id,
        toArea = Card.PlayerHand,
        moveReason = fk.ReasonJustMove,
        proposer = player.id,
        skillName = chengshang.name,
      })
    else
      player:setSkillUseHistory(chengshang.name, 0, Player.HistoryPhase)
    end
  end,
})

chengshang:addEffect("maxcards", {
  name = "#joy__chengshang_max",
  exclude_from = function(self, player, card)
    return card:getMark("@@joy__chengshang-turn") > 0
  end,
})

return chengshang